//=============================================================================
//
// lua/Main.lua
// 
// Created by Max McGuire (max@unknownworlds.com)
// Copyright 2010, Unknown Worlds Entertainment
//
// This script is loaded when the game first starts. It handles creation of
// the main menu.
//=============================================================================

// Set the name of the VM for debugging
decoda_name = "Main"

Script.Load("lua/Globals.lua")
Script.Load("lua/MainMenu.lua")

mods = { "ns2", "faceoff", "MvM"}
maps = 
    { 
        { name = "Tram",             fileName = "ns2_tram.level" },
        { name = "Rockdown",         fileName = "ns2_rockdown.level" },
        { name = "CampaignTest",         fileName = "ns2_cooptest.level" },
        { name = "Junction",         fileName = "ns2_junction.level" }
    }

/**
 * Called when the user types the "map" command at the console.
 */
function OnCommandMap(mapFileName)    
    MainMenu_HostGame(mapFileName)
end

/**
 * Called when the user types the "connect" command at the console.
 */
function OnCommandConnect(address, password)
    MainMenu_SBJoinServer(address, password)
end

/**
 * Called when the user types the "exit" command at the console or clicks the exit button.
 */
function OnCommandExit()
    Main.Exit()
end

/**
 * Called when the client is disconnected from the server.
 */
function OnClientDisconnected(reason)

    // Restore the main menu.
    
    Main.SetMouseVisible(true)
    Main.SetMouseCaptured(false)
    
    Main.SetMenu( kMainMenuFlash )
    MainMenu_SetAlertMessage(reason)
    
end

Event.Hook("Console_connect",  OnCommandConnect)
Event.Hook("Console_map",  OnCommandMap)
Event.Hook("Console_exit", OnCommandExit)
Event.Hook("Console_quit", OnCommandExit)
Event.Hook("ClientDisconnected", OnClientDisconnected)

Main.SetMenu( kMainMenuFlash )